import ItemX from "./entity/ItemX";
import UnitX from "./entity/UnitX";
import EventManager from "./event/EventManager";
import EventMap from "./event/EventGMap";
import DotEvent from "./event/eventdef/DotEvent";
import DmgExecutor from "./module/dmgabout/DmgExecutor";
import DmgFormula from "./module/dmgabout/DmgFormula";
import ItemXManager from "./module/obj_container/ItemXManager";
import UnitXManager from "./module/obj_container/UnitXManager";
import InitAllTrgExector from "./trigger/InitAllTrgExector";
import L_Math from "./utils/L_Math";
import L_String from "./utils/L_String";
import XBuff from "./event/eventdef/XBuff";
import L_Run from "./utils/L_Run";
import NoDefChargedUpEvent from "./event/eventdef/NoDefChargedUpEvent";
import CrackStrikeExecutor from "./module/crack_strike/CrackStrikeExecutor";
import TenaManager from "./module/crack_strike/TenaManager";
import CommonLoopEvent from "./event/eventdef/CommonLoopEvent";
import ArrowManager from "./module/arrowabout/ArrowManager";
import { XAbilityConfig } from "./config/XAbilityConfig";
import EnvConfig from "./config/EnvConfig";
import RewardManager from "./module/reward_about/RewardManager";
import { IMDSkillConfig } from "./config/SkillConfig";
import LuaTimer from "./utils/LuaTimer";
import SkillExecutor from "./skill/SkillExecutor";
import PlayerLearnedSkillsManager from "./skill/playerheroskillmanager/PlayerLearnedSkillsManager";



export function mapInit(){
    console.log("开始注册初始化函数")

    InitAllTrgExector.initAllTrg();

    // //初始化事件容器
    EventManager.init()


    // let ux:UnitX=UnitXManager.getUnitxAutoInitNil(CreateUnit(Player(0),L_Math.ID2I('A001'),0,0,0));
    // console.log("ux hero:",L_String.getObjJSONStr(ux))

    let ix:ItemX | undefined=ItemXManager.getItemxAutoInitNil(CreateItem(L_Math.ID2I('I01O'),0,0),{attrs:{str:1,agi:1,int:1}})
    ItemXManager.enhItem(1,null,ix.item,{attrs:{atk:5,def:5}})




}

export function mapInitxxx(){
    // let h1:Hero =new Hero("关羽");
    // h1.weapons=[new Weapon("青龙偃月刀",98),new Weapon("赤兔",98)]
    // h1.tags=["武圣","二爷"]
    // h1.atten=new Hero("周仓"); 
    // h1.atten.tags=["山贼"]
    // let h2:Hero =new Hero("赵云");
    // h2.agi=10;
    // h2.str=10;
    // h2.int=10;
    // h2.tags=["白马银枪","一身是胆x"]


    // console.log("hero1:",L_String.getObjJSONStr(h1))
    // console.log("hero2:",L_String.getObjJSONStr(h2))

    // let tSet:Set<number>=new Set();
// tSet.add(12);
// tSet.add(13);

// console.log(L_String.getObjJSONStr(tSet))

// let xMap:Map<string,Hero>=new Map();
// xMap.set("l01",h1)
// xMap.set("l02",h2)
// console.log(L_String.getObjJSONStr(xMap))


// 调用CJ API
 //DisplayTextToPlayer(Player(0),1,1,"红花")

//  console.log("hero2 name:",h2.name)

 //console.log(LTF.ID2I('I01O'))
 //BJ_FUNC.CreateUnitX(null, 3399, 0, 0, 0)


//  console.log(L_Math.ID2I('I01O'))
//  console.log(L_Math.I2ID(1227895416))


//  console.log("---->合并属性：")
//  let ov={atk:10,def:8,dt_res:{fire:5,dark:-3},kp:[9],eqp:[{name:"qq",v:5}]};
//  let iv=  {atk:-3,def:6,hp:20,mp:20,kp:[0,2,3],dt_res:{fire:7,dark:10,ice:11},eqp:[{name:"aa",v:2}]}
//  L_AttrControlUtil.mergeField(ov,iv,AttrChangeEnum.INCREASE)
 // console.log(LT_FUNC.getObjJSONStr(ov))
 //console.log(L_String.getObjJSONStr(ov))


//  console.log("enum比对:",UNIT_BAJ_ATTR_CONFIG.hp==UNIT_BAJ_ATTR_CONFIG.atk)
 
 
//  let ux:UnitX=new UnitX({},{attrs:{atk:2,def:8}},1155,"杂鱼1");
//  //创建单位 实例unitx对象 并且为单位注册初始属性
// //let ux:UnitX=UnitXManager.getUnitxAutoInitNil(CreateUnit(Player(0),L_Math.ID2I('A001'),0,0,0),{attrs:{atk:100,def:100}});
// //增加单位属性
// ux.incrUnitAttrs({attrs:{def:5,atk:10,hp:100,mp:100,str:10,int:10},dtRes:{fire:5},dtEnh:{ice:5}})
// //减少单位属性
// ux.redcUnitAttrs({attrs:{def:5,str:2,atk:5,hp:40,mp:60},dtRes:{dark:5},dtEnh:{ice:1,fire:3}})
// console.log(L_String.getObjJSONStr(ux))






//   let au:UnitX=new UnitX({},{attrs:{atk:2,def:2}},1155,"杂鱼1");
//let nui:UnitX=new UnitX(CreateUnit(Player(0),L_Math.ID2I('A001'),0,0,0),undefined,"测试单位",{})

// UnitFieldChangeEx.setUnitStatCByUnitx(nui,UNIT_FIELD_CONFIG.str,100)
// UnitFieldChangeEx.setUnitStatCByUnitx(nui,UNIT_FIELD_CONFIG.int,123)
// UnitFieldChangeEx.setUnitStatCByUnitx(nui,UNIT_FIELD_CONFIG.atk,1060)
// UnitFieldChangeEx.setUnitStatCByUnitx(nui,UNIT_FIELD_CONFIG.def,152) 
// UnitFieldChangeEx.incUnitStatHpMpByUnitx(nui,UNIT_FIELD_CONFIG.hp,1000) 
// UnitFieldChangeEx.incUnitStatHpMpByUnitx(nui,UNIT_FIELD_CONFIG.mp,1000) 


// let subArr=["黄","天"]
// // XArr.push(...subArr)
// L_Array.pushByDec(ux.a_skill,subArr)
// console.log(L_String.getObjJSONStr(ux.a_skill))

// L_Array.removeByDec(ux.a_skill,["初","天"])
// console.log(L_String.getObjJSONStr(ux.a_skill))

// let nix:EnhIndexItemXRel | null=PlayerEnhManager.getPlayerEnhItemTypeId(1);
// PlayerEnhManager.getPlayerEnhItemTypeId(1);
// PlayerEnhManager.getPlayerEnhItemTypeId(1);
// PlayerEnhManager.getPlayerEnhItemTypeId(1);
// PlayerEnhManager.destoryEnhItemRel(2)
// PlayerEnhManager.getPlayerEnhItemTypeId(1);
// PlayerEnhManager.getPlayerEnhItemTypeId(1);
// PlayerEnhManager.destoryEnhItemRel(3)
// PlayerEnhManager.getPlayerEnhItemTypeId(1);
// PlayerEnhManager.getPlayerEnhItemTypeId(1);




//-----------------装备强化测试区-----------------------------------------
// let ix:ItemX=ItemXManager.getItemxAutoInitNil(95,{attrs:{atk:100}});
// //强化物品属性
// //ix.incrItemAttrs({attrs:{def:15,atk:1001,hp:580},dtRes:{nothing:5},dtEnh:{nothing:5}})

// console.log("初始物品:",L_String.getObjJSONStr(ix))

// ix!=ItemXManager.enhItem(1,0,ix,{attrs:{atk:5,def:5}})
// //console.log("++强化后物品:",L_String.getObjJSONStr(ix))

// ix!=ItemXManager.enhItem(1,0,ix,{attrs:{atk:5,def:5}})
// //console.log("++强化后物品:",L_String.getObjJSONStr(ix))

// ix!=ItemXManager.enhItem(1,0,ix,{attrs:{atk:5,def:5,hp:120,mp:13,agi:33,str:33,'cri':10},'dtEnh':{'poison':5,'dark':3,all_nphy_ele:15}})
// //console.log("++强化后物品:",L_String.getObjJSONStr(ix))

// // ItemXManager.showStat()
// //  PlayerEnhManager.showStat()

// console.log("--->装备属性描述:\n",ix.getItemxDesc())

//-----------------装备强化测试区 结束-----------------------------------------


// //item全局管理池创建单位属性对象
// let au:UnitX=UnitXManager.getUnitxAutoInitNil({},{attrs:{cri:2,'cri_mul':2}})
// //单位获取装备增加属性
// au.incrUnitAttrs(ix)
// console.log(">>>>获取装备后单位属性:",L_String.getObjJSONStr(au))

// au.redcUnitAttrs(ix)
// console.log(">>>>失去装备后单位属性:",L_String.getObjJSONStr(au))

//CreateUnit(Player(0),L_Math.ID2I('A001'),0,0,0)
let u1=L_Run.createUnitAtXY(0,'A001',0,0,0,88)
let ua:UnitX=UnitXManager.getUnitxAutoInitNil(u1,{attrs:{atk:-200,hit:50},dtEnh:{dark:200,ice:33,fire:200},dtRes:{all_nphy_ele:55}},"关羽")
ua.additDmgEffAddX('phyFireball')
ua.additDmgEffAddX('pyhLightningChain')
ua.incrUnitAttrs({attrs:{cri:35,cri_mul:150}})

let u2=L_Run.createUnitAtXY(1,'A001',0,0,0,99)
let ub:UnitX=UnitXManager.getUnitxAutoInitNil(u2,{attrs:{atk:-300,flee:80,tena:4},dtRes:{dark:110,fire:900}},"吕布")
ub.xAbilitysAddX('fleeMp1')
ub.xAbilitysAddX('fleeMp1')
ub.xAbilitysAddX('fleeMp1')
//ub.xAbilitysAddX('fleeAtkUp1')

ub.xAbilitysRemoveX('fleeMp1')

console.log(ub.xAbilitysTrgTypeArr('flee'))



//  console.log(">>>>>>>>>>>韧性打击1 移除3点")
// TenaManager.reduceUnitTena(ub,3)

// new CommonLoopEvent('SECONDS',3,()=>{
//     console.log(">>>>>>>>>>>韧性打击2 移除4点")
//     TenaManager.reduceUnitTena(ub,4)
// },1).beAddedAndExec()

// ArrowManager.createArrow(ua.unit,ub,true,
//     {commonDmg:false,radius:100,hitCallBack:(ux)=>{
//         console.log(ux.name)
//     },evCallback:{ 
//         startCallback:(arrow)=>{
//             console.log("~~~~~~飞行开始~~~~~")
//         },
//         runCallback:(ux)=>{
//             console.log("~~~~飞行啊~~~~~")
//         },
//         endCallback:(arrow)=>{
//             console.log("~~~~~~飞行结束~~~~~")
//         }
// }} 
// ).angleMoveWithDis(50,0,0,100)





//------------------------timer容器测试区----------------------

// //初始化事件容器
 //let timerx=L_Run.CreateTimer_L(2000,()=>{console.log("测试luatimer!")},3)

 //EventManager.init(12)

//  let bs1=new NoDefChargedUpEvent('SECONDS',1,3,{targetux:ua,runCallback:()=>{
//     console.log("-------蓄力阶段 防御架势降低100！------------")
// },endCallback:()=>{
//     console.log('蓄力技发动成功!')
// },incExtraAttr:{attrs:{def_posture:-100}}})
// bs1.beAddedAndExec() 

// EventManager.startExecutorForTest('SECONDS')
// let ndot=new DotEvent('SECONDS',1,1,{autoExecDmgEff:false,aux:ub,bux:ua,'oriDmg':100,dmgTypeKey:'ice',callback:()=>{
    
//     let crs=CrackStrikeExecutor.execCrackStrike(300,10,ua,ub,10,100,'ice',{attrs:{hit:30}})
//     console.log("-------dddd到期------------",crs)
   
// },extraDmgAttr:{attrs:{hit:300}}})
// ndot.beAddedAndExec()

// //创建事件1
// let dot2=new DotEvent('SECONDS',4,2,{autoExecDmgEff:true,aux:ua,bux:ub,'oriDmg':200,dmgTypeKey:'fire',additTrgProb:100,effectPath:"xxfire.mdl",effAttPoint:'chest'})
// dot2.beAddedAndExec()

//创建事件2
// let dot1=new DotEvent('SECONDS',2,3,{autoExecDmgEff:false,aux:ua,bux:ub,'oriDmg':500,dmgTypeKey:'dark',callback:()=>{
//     console.log("-------2秒一跳 dot打击------------")
//     DmgExecutor.dmgUnitByAbilityDfHit(ua,ub,dot1.dtl.oriDmg,10,dot1.dtl.dmgTypeKey,undefined)
//     // bs1.endImmed()
//     // console.log("dot伤害破招打断")
// }})
// dot1.beAddedAndExec()




//------------------------timer容器测试区 结束----------------------


// new XBuff('BUFF','SECONDS',4,()=>{
//     console.log("获取攻击buff 增加攻击力100")
//     ub.incrUnitAttrs({attrs:{atk:100}})
// },
// ()=>{
//     console.log("失去攻击buff 减少攻击力100")
//     ub.incrUnitAttrs({attrs:{atk:-100}})
// }
// ).beAddedAndExec()



//------------------平砍测试区--------------------------------

// console.log("-------第一次打击------------")
// DmgExecutor.dmgUnitByAbility(ua,ub,100,100,"dark",undefined)

// console.log("-------第二次打击------------")
// DmgExecutor.dmgUnitByAbility(ua,ub,30,100,'death',{attrs:{cri:50,cri_mul:100}})
// console.log("-------第三次打击------------")
// DmgExecutor.dmgUnitByAbility(ua,ub,100,100,"dark",{attrs:{cri:30,cri_mul:200}})

//------------------平砍测试区   结束--------------------------------


//-----------------奖励测试区------------------------
//RewardManager.createRewardForUnit(ua,3)


//-----------------奖励测试区 结束------------------------



//-----------------技能测试---------------------------

//EventManager.init(12)
//请注册 EventManager.init(12)后才可执行SkillEvent

//大火球（直线通用伤害）
//SkillExecutor.execIMDSkillById(ua,'IAXA')
//蛇形波（自定义轨迹）
// SkillExecutor.execIMDSkillById(ua,'SHEW')



//luaTimer坑爹问题 注意timer类型问题 手动找到匹配的类型 否则运行的executor可能不是期望的
//EventManager.startExecutorForTest('TENTH_OF_SEC')

//BOSS蓄力震击（失衡蓄力演示）
// SkillExecutor.execIMDSkillById(ua,'XUZH')
// EventManager.startExecutorForTest('SECONDS')

//-----------------技能测试结束-----------------------


//-------------玩家可学习技能测试--------------
// PlayerLearnedSkillsManager.playerSkillLearnAndSyncHeroData(0,'IAXA',100,ua.unit)
//PlayerLearnedSkillsManager.playerSkillLearnAndSyncHeroData(0,'IAXA',100)




// PlayerLearnedSkillsManager.playerSkillLearnAndSyncHeroData(0,'SHEW',70,ua.unit)
// PlayerLearnedSkillsManager.playerSkillLearnAndSyncHeroData(1,'IAXA',0,ub.unit)
// PlayerLearnedSkillsManager.playerSkillLearnAndSyncHeroData(1,'SHEW',600,ub.unit)

// PlayerLearnedSkillsManager.playerSkillLearnAndSyncHeroData(0,'PIKK',90,ua.unit)
// PlayerLearnedSkillsManager.playerSkillLearnAndSyncHeroData(0,'PIKK',500)
// PlayerLearnedSkillsManager.playerSkillLearnAndSyncHeroData(0,'IAXA',0,ua.unit)
//------------玩家可学习技能测试结束-------------

}


//  EnvConfig.devMod=true;
 //mapInitxxx()




 
